package service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

import dao.WaiterDao;
import dao.impl.WaiterDaoImpl;
import entiey.Waiter;
import service.WaiterService;

public class WaiterServiceImpl implements WaiterService{

	private WaiterDao wdao = new WaiterDaoImpl();
	
	@Override
	public boolean saveWaiter(Waiter w) {
		
		return wdao.add(w)>0;
	}

	@Override
	public boolean updateWaiter(Waiter w) {
		return wdao.update(w)>0;
	}

	@Override
	public boolean deleteWaiter(int no) {
		return wdao.delete(no)>0;
	}

	@Override
	public Waiter findById(int waiterNo) {
		return wdao.findById(waiterNo);
	}

	@Override
	public List<Waiter> findAllWaiter() {
		return wdao.findAll();
	}

	@Override
	public List<Waiter> query(String name) {
		List<Waiter> list = new ArrayList<Waiter>();
		
//		String Search_id = "\\d{1,}";
		String Search_name = ".*[\\u4e00-\\u9fa5].*";

		if(Pattern.matches(Search_name, name)){
			
			list=wdao.findByName(name);
		}else {
			list = findAllWaiter();
		}
		return list;
	}

}
